namespace SIMCIntegratedReports
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Telerik.Reporting;
    using Telerik.Reporting.Drawing;
    using System.Globalization;
    using System.Data;
    using System.Collections.Generic;
    using SIMCFachadaNegocio;
    using SIMCObjetoNegocio;

    /// <summary>
    /// Summary description for rptMovimientoCuenta.
    /// </summary>
    public partial class rptMovimientoCuenta : Telerik.Reporting.Report
    {
        public double x;
        CultureInfo myCulture = new CultureInfo("es-VE");

        public rptMovimientoCuenta()
        {
            /// <summary>
            /// Required for telerik Reporting designer support
            /// </summary>
            x = 0;
           
            InitializeComponent();
            
        }

        private void txtSaldo_ItemDataBound(object sender, EventArgs e)
        {
            //try
            //{
            //    Telerik.Reporting.Processing.TextBox processingText = (Telerik.Reporting.Processing.TextBox)sender;

            //    double monto = (double)processingText.DataObject["MONTO"];

            //    x = monto + x;
            //    processingText.Value = x.ToString();
            //}
            //catch (Exception ex)
            //{

            //    throw;
            //}
        }

        private void rptMovimientoCuenta_ItemDataBound(object sender, EventArgs e)
        {
            
        }

        private void detail_ItemDataBound(object sender, EventArgs e)
        {
            //try
            //{
            //    x = 0;
            //}
            //catch (Exception ex)
            //{
                
            //    throw;
            //}
        }

        private void rptMovimientoCuenta_NeedDataSource(object sender, EventArgs e)
        {
            FachadaPersona fachadaPersona = new FachadaPersona();
            FachadaPortafolio fachadaportafolio = new FachadaPortafolio();

            int idCuenta = Convert.ToInt32(this.ReportParameters["IdCuenta"].Value);
            DateTime fecha = Convert.ToDateTime(this.ReportParameters["FechaCorte"].Value.ToString());
            int IdTitular = Convert.ToInt32(this.ReportParameters["IdTitular"].Value);

            PersonaPlana persona = fachadaPersona.BuscarPersonaPlana(IdTitular);
            txtNombre.Value = persona.NombreCorto;

            List<Movimiento> movimientos = fachadaportafolio.BuscarMovimientos(idCuenta, fecha, IdTitular);

            double temp = 0;
            foreach (Movimiento row in movimientos)
            {
                row.Monto = (row.Signo == "-") ? row.Monto : row.Monto * -1;
                row.Saldo += row.Monto + temp;
                temp = row.Saldo;
            }
            this.DataSource = movimientos;
        }
    }
}